package com.wenshi.web.controller.device;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wenshi.common.core.domain.AjaxResult;
import com.wenshi.system.domain.HydrogenProductionRates;
import com.wenshi.system.domain.SysDevice;
import com.wenshi.system.service.IHydrogenProductionRateService;
import com.wenshi.system.service.ISysDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/hydrogen")
@Slf4j
public class SysHydrogenController {

    @Autowired
    private IHydrogenProductionRateService irateService;
    @Autowired
    private ISysDeviceService iSysDeviceService;

    @GetMapping("/getHydrogenRates")
    @CrossOrigin
    public AjaxResult getHydrogenRates(String deviceIp){
        SysDevice sysDevice = iSysDeviceService.getByDeviceIp(deviceIp);
        QueryWrapper<HydrogenProductionRates> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("device_id",sysDevice.getDeviceId());
//        LocalDate localDate = LocalDate.now();
//        LocalTime min = LocalTime.MIN;
//        LocalTime max = LocalTime.MAX;
//        LocalDateTime localDateTimeMin = LocalDateTime.of(localDate, min);
//        LocalDateTime localDateTimeMax = LocalDateTime.of(localDate, max);
//        Date date = DateUtils.toDate(localDateTimeMin);
//        Date date1 = DateUtils.toDate(localDateTimeMax);
//        queryWrapper.ge("timestamp",date);
//        queryWrapper.le("timestamp",date1);
        List<HydrogenProductionRates> list = irateService.list(queryWrapper);
        return AjaxResult.success(list);
    }
}
